<?php
	ob_start();
	class CommentsController extends AppController{
		var $name='Comments';
		//var $name = 'Products';	
		var $helpers = array('Html','Ajax','Javascript','Form','Session');
		
		function index($id=null){
		$this->layout ="home";
			$this->Comment->id = $id;
			$this->set('commentread',$this->Comment->read());
			$this->set('comment',$this->Comment->find('all'));
		}
		function save(){
		$id = null;
		$customer_id =$_SESSION['customer_id'];
		$content = $_REQUEST['content'];
		$product_id= $_REQUEST['pid'];
		$cm_date = date("Y-m-d");
		$status = 1;
		if(($id != null) && ($id != "")){
			$this->Comment->id = $id;
			$this->Comment->set('customer_id',$customer_id);
			$this->Comment->set('cm_content',$content);
			$this->Comment->set('product_id',$product_id);
			$this->Comment->set('date',$cm_date);
			$this->Comment->set('status',$status);
			$this->Comment->save();
		}
		else
		{
			$this->Comment->create();
			$this->Comment->set('customer_id',$customer_id);
			$this->Comment->set('cm_content',$content);
			$this->Comment->set('product_id',$product_id);
			$this->Comment->set('date',$cm_date);
			$this->Comment->set('status',$status);
			$this->Comment->saveAll();
		}
		$this->redirect(array("action" => "index"));
		}
		function delete() {
		$id= $_REQUEST['id'];
		if($id !=null && $id !=""){
		$this->Comment->delete($id);
		$this->Session->setFlash(__('ban co chac xoa san pham khong', true));
		$this->redirect(array("action"=>"index"));
		}
	}
	}
?>